#include<stdio.h>
#include<stdlib.h>
#define N 100

int main()
{
	int a[N];
	int b[N];
	int c[N];
	int k;
	int j = 0;
	int i = 0;
	int t;
	
	scanf("%d", &a[i]);
	
	while(a[i] != -1)
	{
		i++;
		scanf("%d", &a[i]);
	}
	
	i = 0;
	scanf("%d", &b[i]);
	
	while(b[i] != -1)
	{
		i++;
		scanf("%d", &b[i]);
	}
	
	for(i=0; a[i]!=-1; i++)
	{
		for(k=0; b[k]!=-1; k++)
		{
			if(a[i] == b[k])
			{
				c[j] = a[i];
				j++;
				break;
			}
		}
	}
	
	for(i=1; i<j; i++)
	{
		for(k=0; k<=j-i-1; k++)
		{
			if(c[k] > c[k+1])
			{
				t = c[k];
				c[k] = c[k+1];
				c[k+1] = t;
			}
		}
	}
	
	for(i=0; i<j; i++)
	{
		printf("%d ", c[i]);
	}
	
	return 0;
}

